import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { LittleThingModule } from './modules/PC/little-thing/little-thing.module';
import { UserModule } from './modules/PC/user/user.module';
import { WeChatModule } from './modules/WeChat/index.module';
// import { UserModule } from './user/user.module';
import { getBaseConfig, getConfig } from './utils';

@Module({
  imports: [
    ConfigModule.forRoot({
      ignoreEnvFile: true,
      isGlobal: true,
      load: [getBaseConfig, getConfig],
    }),
    TypeOrmModule.forRootAsync({
      imports:[ConfigModule],
      inject:[ConfigService],
      useFactory: (configService: ConfigService) => ({
        autoLoadEntities: true,
        type: configService.get('MYSQL_CONFIG').type,
        host: configService.get('MYSQL_CONFIG').host,
        port: configService.get('MYSQL_CONFIG').port,
        username: configService.get('MYSQL_CONFIG').username,
        password: configService.get('MYSQL_CONFIG').password,
        database: configService.get('MYSQL_CONFIG').database,
        synchronize: configService.get('MYSQL_CONFIG').synchronize,
        logging: configService.get('MYSQL_CONFIG').logging,
        // entities: [join(__dirname, '../', '**/**.entity{.ts,.js}')],
        timezone: configService.get('MYSQL_CONFIG').timezone, // 时区
      }),
    }),
    UserModule,
    LittleThingModule,
    WeChatModule
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
